// 这个模块是管理动态路由响应式数据处理的
import { constantRoutes, asyncRoutes } from '@/router'
console.log(constantRoutes)
const state = {
  routes: [...constantRoutes]
}
const mutations = {
  addAsyncRoutes(state, filterRoutes) {
    // state.routes.push(...filterRoutes, { path: '*', redirect: '/404', hidden: true })
    state.routes = [...constantRoutes, ...filterRoutes, { path: '*', redirect: '/404', hidden: true }]
  }
}
const actions = {
  filterRoutes(context, menus) {
    //  过滤路由
    const filterRoutes = asyncRoutes.filter(item => menus.includes(item.children[0].name))
    context.commit('addAsyncRoutes', filterRoutes)
    return filterRoutes
  }
}
export default {
//  开启命名空间
  namespaced: true,
  state,
  mutations,
  actions
}
